<template>
	<view class="setting-container" :style="{height: `${windowHeight}px`}">
		<view class="menu-list">
			<view class="list-cell list-cell-arrow" @click="handleToPwd">
				<view class="menu-item-box">
					<view class="iconfont icon-password menu-icon"></view>
					<view>修改密码</view>
				</view>
			</view>
			<view class="list-cell list-cell-arrow" @click="handleToEditInfo">
				<view class="menu-item-box">
					<view class="iconfont icon-bianjiziliao- menu-icon"></view>
					<view>编辑资料</view>
				</view>
			</view>
			<!-- #ifdef APP-PLUS -->
			<view class="list-cell list-cell-arrow" @click="checkVersion">
				<view class="menu-item-box">
					<view class="iconfont icon-jianchagengxin menu-icon"></view>
					<view>检查更新</view>
				</view>
			</view>
			<!-- #endif -->
			<view class="list-cell list-cell-arrow" @click="handleCleanTmp">
				<view class="menu-item-box">
					<view class="iconfont icon-clean menu-icon"></view>
					<view>清理缓存</view>
				</view>
			</view>
		</view>
		<!-- <view class="cu-list menu">
      <view class="cu-item item-box">
        <view class="content text-center" @click="handleLogout">
          <text class="text-black">退出登录</text>
        </view>
      </view>
    </view> -->
	</view>
	<view>
		<!-- <uni-popup ref="popup" type="dialog">
  	    <uni-popup-dialog type="info" cancelText="关闭" confirmText="退出"
  	                      title="通知" content="确定注销并退出系统吗" 
  	    				  @confirm="dialogConfirm"
  	                      @close="dialogClose">
  	    </uni-popup-dialog>
  	  </uni-popup> -->

		<geek-upgrade :type="upgradeType" :version="version" :url="upgradeUrl" title="发现新版本!" :content="upgradeContent"
			ref="upgrade"></geek-upgrade>
	</view>
</template>

<script setup>
	import _ from 'lodash'
	import {
		ref
	} from "vue";
	import config from '@/config.js'
	import store from '@/store'
	import Updater from '@/uni_modules/guyue-updater/index';

	const windowHeight = ref(uni.getSystemInfoSync().windowHeight);
	const popup = ref(null);
	const context = ref({
		"isCheckVersion": false,
		"innerVer": 0,
		"version": 0
	});

	const upgrade = ref(null)
	const version = ref('')
	const upgradeType = ref('pkg') //pkg 整包 wgt 升级包
	const upgradeContent = ref('') //更新内容
	const upgradeUrl = ref('') //更新地址

	function handleToPwd() {
		uni.navigateTo({
			url: '/pages_mine/pages/pwd/index'
		});
	};

	function handleToEditInfo() {
		uni.navigateTo({
			url: '/pages_mine/pages/info/edit'
		});
	};

	function checkVersion() {
		// 获取版本信息
		// #ifdef APP-PLUS
		plus.screen.lockOrientation('portrait-primary') // 竖屏锁定
		plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
			uni.request({
				url: config.baseUrl + '/seller/upgrade?_t=' + new Date().getTime(), //版本检测
				data: {},
				header: {},
				success: (result) => {
					if (result.data.code === 200) {
						// widgetInfo.version
						const installPackage = _.get(result.data, 'data', {}) || {}
						if (installPackage.version - widgetInfo.versionCode >
							0) { // 如果最新版本大于现在已经安装的App的版本
							upgradeType.value = 'pkg'
							version.value = `v${_.get(installPackage, 'name', '')}`
							upgradeContent.value = _.get(installPackage, 'remark', '')
							upgradeUrl.value = _.get(installPackage, 'downloadUrl', '')
							upgrade.value.show()
						} else {
							uni.showToast({
								title: '当前已是最新版本',
								icon:"none"
							})
						}
					}
				}
			})
		})
		// #endif
	}

	function handleCleanTmp() {
		store.dispatch('cleanStorage').then(() => {
			uni.showToast({
				title: '清理完成'
			});
		}).catch(() => {
			uni.showToast({
				title: '清理失败'
			});
		});
	};
	// function handleLogout() {
	// 	  popup.value.open();
	// };
	// function dialogConfirm() {
	// 	//console.log('----------------点击确认------------')
	// 	store.dispatch('LogOut').then(() => {
	// 			uni.reLaunch({
	// 				url: '/pages/login'
	// 			});
	// 	})
	// };
	// function dialogClose() {
	// 	//console.log('点击关闭')
	// };
</script>

<style lang="scss" scoped>
	.page {
		background-color: #f8f8f8;
	}

	.item-box {
		background-color: #FFFFFF;
		margin: 30rpx;
		display: flex;
		flex-direction: row;
		justify-content: center;
		align-items: center;
		padding: 10rpx;
		border-radius: 8rpx;
		color: #303133;
		font-size: 32rpx;
	}
</style>